﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.IO;

namespace DLL.Entities
{
    public class XMLHandler
    {
       
        public static bool WriteXML(object savedObj, string fileToSave, XmlSerializer serializer)
        { 
          try
             { 
                TextWriter textWriter = new StreamWriter(fileToSave);
                serializer.Serialize(textWriter, savedObj); 
                textWriter.Close();
                return true;
          } 
          catch (Exception ex)
          { 
              Utility.LogFile(ex.ToString()); return false;
          }
        }
        public static object ReadXML(string fileToOpen, XmlSerializer deSerializer)
        {
            try
            {
                StreamReader sr = new StreamReader(fileToOpen);
                // where you set the serializer destination 
                // data to something so you set it to saveobj 
                return (object)deSerializer.Deserialize(sr);
                //TextWriter textWriter = new StreamWriter(fileToSave);
                //serializer.Serialize(textWriter, savedObj); textWriter.Close();
                //return true;

            }
            catch
            {
                return null;
            }
        }
    }
}
